<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:pe="http://primefaces.org/ui/extensions">

    <h:body>
        <ui:composition template="/resources/template/template.xhtml">
            <ui:define name="content">
                <h:form>
                    <p:panel header="INWARD CASH DUE">
                        <f:facet name="header">
                            <h:outputLabel value="INWARD CASH DUE"/>

                            <h:panelGrid columns="2" >

                                <h:outputLabel value="From" ></h:outputLabel>
                                <p:calendar value="#{creditCompanyDueController.fromDate}" pattern="dd/MMM/yyyy - hh:mm:ss a" ></p:calendar>
                                <h:outputLabel value="To" ></h:outputLabel>
                                <p:calendar value="#{creditCompanyDueController.toDate}" pattern="dd/MMM/yyyy - hh:mm:ss a" ></p:calendar>

                                <p:outputLabel value="Admission Type"/>
                                <p:selectOneMenu value="#{creditCompanyDueController.admissionType}">
                                    <f:selectItem itemLabel="All Admission Type"/>
                                    <f:selectItems  value="#{admissionTypeController.items}" var="myItem" 
                                                    itemValue="#{myItem}" itemLabel="#{myItem.name}"></f:selectItems>
                                </p:selectOneMenu>

                                <h:outputLabel value="BHT Type : " ></h:outputLabel>
                                <p:selectOneMenu   id="cmbBhtType" value="#{creditCompanyDueController.paymentMethod}"  >
                                    <f:selectItem itemLabel="All BHT Types" />                           
                                    <f:selectItems value="#{enumController.paymentMethodForAdmission}" />
                                </p:selectOneMenu>


                                <h:outputLabel value="Company Name : " style="min-width: 100px;"  />  
                                <p:autoComplete id="acCreditCompany" forceSelection="true" style="text-align: right;"
                                                value="#{creditCompanyDueController.institution}"  
                                                completeMethod="#{creditCompanyController.completeCredit}" 
                                                var="ix" itemLabel="#{ix.name}" 
                                                itemValue="#{ix}" size="30" >  
                                    <f:ajax event="itemSelect" execute="@this"  ></f:ajax>
                                </p:autoComplete>


                            </h:panelGrid>
                            <p:spacer width="120" height="1"/>
                            <p:commandButton ajax="false" value="Process" action="#{creditCompanyDueController.createInwardCashDue()}"/>
                            <p:commandButton value="Excel" ajax="false" actionListener="#{creditCompanyDueController.createInwardAgeDetailAnalysis}" >
                                <pe:exporter target="lstDue" fileName="inward_due_age_credit_company_detail" type="xlsx" />
                            </p:commandButton>
                        </f:facet>
                        <p:dataTable id="lstDue" value="#{creditCompanyDueController.patientEncounters}"  var="p" rowIndexVar="i" >
                            <p:column>
                                <p:outputLabel value="#{i+1}" />
                            </p:column>
                            <p:column headerText="BHT">
                                <p:outputLabel value="#{p.bhtNo}" />
                            </p:column>
                            <p:column headerText="Company">
                                <p:outputLabel value="#{p.creditCompany.name}" />
                            </p:column>
                            <p:column headerText="Admissted At">
                                <p:outputLabel value="#{p.dateOfAdmission}" >
                                    <f:convertDateTime pattern="yy MM dd hh:mmss a" />
                                </p:outputLabel>
                            </p:column>
                            <p:column headerText="Discharged At">
                                <p:outputLabel value="#{p.dateOfDischarge}" >
                                    <f:convertDateTime pattern="yy MM dd hh:mmss a" />
                                </p:outputLabel>
                            </p:column>
                            <p:column headerText="Final Total"  style="text-align: right;">
                                <h:outputLabel value="#{p.finalBill.netTotal}">
                                    <f:convertNumber pattern="#,##0.00"/>
                                </h:outputLabel>
                                <f:facet name="footer">
                                    <h:outputLabel value="#{creditCompanyDueController.billed}">
                                        <f:convertNumber pattern="#,##0.00"/>
                                    </h:outputLabel>
                                </f:facet>
                            </p:column>
                            <p:column headerText="Paid By Patient" style="text-align: right;">
                                <h:outputLabel value="#{p.finalBill.paidAmount}">
                                    <f:convertNumber pattern="#,##0.00"/>
                                </h:outputLabel>
                                <f:facet name="footer">

                                    <h:outputLabel value="#{creditCompanyDueController.paidByPatient}">
                                        <f:convertNumber pattern="#,##0.00"/>
                                    </h:outputLabel>
                                </f:facet>
                            </p:column>
                            <p:column headerText="Paid By Company"  style="text-align: right;">
                                <h:outputLabel value="#{p.paidByCreditCompany}">
                                    <f:convertNumber pattern="#,##0.00"/>
                                </h:outputLabel>                            
                                <f:facet name="footer">
                                    <h:outputLabel value="#{creditCompanyDueController.paidByCompany}">
                                        <f:convertNumber pattern="#,##0.00"/>
                                    </h:outputLabel>
                                </f:facet>
                            </p:column>


                            <p:column headerText="Due"  style="text-align: right;" >

                                <h:outputLabel value="#{(p.finalBill.netTotal-(p.finalBill.paidAmount+p.paidByCreditCompany)) gt 0? (p.finalBill.netTotal-(p.finalBill.paidAmount+p.paidByCreditCompany)):0.00}">
                                    <f:convertNumber pattern="#,##0.00"/>
                                </h:outputLabel>
                                <f:facet name="footer">
                                    <h:outputLabel value="#{creditCompanyDueController.billed-(creditCompanyDueController.paidByCompany+creditCompanyDueController.paidByPatient)}">
                                        <f:convertNumber pattern="#,##0.00"/>                                    
                                    </h:outputLabel>
                                </f:facet>
                            </p:column>
                        </p:dataTable>

                    </p:panel>
                </h:form>
            </ui:define>


        </ui:composition>

    </h:body>
</html>
